<!--
 * @Author: wcx 1055127249@qq.com
 * @Date: 2024-12-30 09:37:18
 * @LastEditors: wcx 1055127249@qq.com
 * @LastEditTime: 2025-01-20 14:07:19
 * @FilePath: \my-project\src\views\Login.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <el-card class="login-card" shadow="hover">
    <div style="margin: 5px 5px 20px;">用户登录</div>
    <el-form class="login-form" ref="form" :model="form">
      <el-form-item label="账号" class="login-form-item" prop="username">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" class="login-form-item" prop="password">
        <el-input v-model="form.password" type="password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button style="width: 100%;" type="primary" @click="login">登录</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>
<script>
export default {
  name: 'Login',
  data() {
    return {
      form: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    async login() {
      await this.$refs.form.validate()
      this.$router.push({ path: '/home' })
    }
  }
}
</script>

<style lang="scss">
.login-card {
  top: 50%;
  left: 50%;
  position: fixed;
  transform: translate(-50%, -50%);
  border-radius: 10px;
  .login-form {
    width: 300px;
    padding: 0 5px;
  }
  .login-form-item {
    .el-form-item__label {
      line-height: 1;
      margin-bottom: 10px;
    }
  }
}
</style>